package org.bbx.autoops.utils;


import freemarker.template.Template;
import freemarker.template.TemplateException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;

import java.io.IOException;

@Slf4j
public class ProcessContent {

    private static final String enter = "\r\n";


    /**
     * 给模板变量赋值
     *
     * @param b 赋值后的模板内容字符串
     * @param t 模板
     * @param o 变量对象
     * @throws TemplateException
     * @throws IOException
     */
    public static void process(StringBuilder b, Template t, Object o) {
        try {
            String s = FreeMarkerTemplateUtils.processTemplateIntoString(t, o);
            b.append(s)
                    .append(enter);
        } catch (IOException | TemplateException e) {
            log.error(e.getMessage());
        }
    }


}
